//取消扩充
function cancelAdd(){
    var codeBox = document.getElementsByClassName("add-code-box-border")[0];
    codeBox.style.display="none";
}
//扩充
function codeAdd(){
    var codeBox = document.getElementsByClassName("add-code-box-border")[0];
    codeBox.style.display="block";
}
//创建邀请码
function createCode(element){
    var num = element.previousElementSibling.value;
    var classId = element.nextElementSibling.value;
    if(num!=""){
        fetch('/createCode?classId=' + classId+'&num='+num)
        .then(function (res) {
            return res.text();
        })
        .then(function (data) {
            if (data == "success") {
                alert("成功添加");
                window.location.reload();
            } else if(data == "full"){
                alert("邀请码已达最大数量");
            }else{
                alert("未知错误");
            }
        }).catch(function (e) {
            alert("error:" + e);
        })
    }else{
        alert("数量不能为空");
    }
}